home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls074c.sunsparc.Z / tls074c.sunsparc / lib / vtcl / examples / msg.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  3.2 KB  |  126 lines

  1. #!/bin/vtcl
  2. # ---------------------------------------------------------------------
  3. # Copyright 1994 by SCO, Inc.
  4. # Permission to use, copy, modify, distribute, and sell this software
  5. # and its documentation for any purpose is hereby granted without fee,
  6. # provided that the above copyright notice appear in all copies and that
  7. # both that copyright  notice  and  this  permission  notice  appear  in
  8. # supporting documentation, and that the name  of  SCO  not  be used  in
  9. # advertising or publicity pertaining  to distribution of  the  software
  10. # without   specific,   written  prior   permission.    SCO   makes   no
  11. # representations  about  the  suitability  of  this  software  for  any
  12. # purpose.  It is provided "as is" without express or implied warranty.
  13. # ---------------------------------------------------------------------
  14.  
  15. # Demo        : msg.tcl
  16. # Description    : Demo of all the Motif dialog boxes.
  17. #  
  18. # Note        : Good example of building a command, later to be
  19. #          invoked via the "eval" command.
  20.  
  21. # Close connection and exit Visual Tcl interpreter.
  22. proc CloseCB { cbs } {
  23.     VtClose; exit 0
  24. }
  25. #
  26. # Minimal test of messagebox the idea here is to display all the different
  27. # types at once with different options, like new lines, blank titles, etc.
  28. #
  29.  
  30. proc LabelText {parent label text} {
  31.         VtLabel $parent.label \
  32.         -label $label
  33.         set textWidget [VtText $parent.textWidget \
  34.         -value $text \
  35.         -verticalScrollBar True \
  36.              -rightSide FORM  \
  37.         -rows 3 \
  38.         ]
  39.  
  40.     return $textWidget
  41. }
  42.  
  43. # Grab the text stored in the text widget,
  44. # Build the dialog, passing the button option (i.e. -ok, -cancel, -help)
  45. # stored in the userData field.
  46. #
  47. proc mkDlog {cmd buttonList textWidget cbs} {
  48.     set txt [VtGetValues $textWidget -value]
  49.     set parent [keylget cbs widget]
  50.  
  51.     lappend cmd $parent.$cmd -message $txt 
  52.  
  53.     # look at each button (ok, cancel, help) and determine
  54.     # if it should be displayed.
  55.     #
  56.     foreach button $buttonList {
  57.         if { [VtGetValues $button -value]} {
  58.             set resource [VtGetValues $button -userData]
  59.             lappend cmd $resource
  60.         }
  61.     }
  62.  
  63.     set dialog [eval $cmd]
  64.     VtShow $dialog
  65. }
  66.  
  67. # Open connection to the Visual Tcl display engine.
  68. #
  69. set app [VtOpen msg]
  70.  
  71. # Build the main dialog.
  72. #
  73. set dlog [VtFormDialog $app.dlog \
  74.     -title "Motif Message Dialogs" \
  75.     -okLabel Quit \
  76.     -okCallback CloseCB \
  77.     -help \
  78.     ]
  79.  
  80. set textWidget [LabelText $dlog "Message Title" "<Put your text here!>"]
  81.  
  82. set rc [VtRowColumn $dlog.rc  \
  83.     -leftSide FORM \
  84.     -below $textWidget \
  85.     -horizontal \
  86.     ]
  87.  
  88. # We'll store the option inside each widget using the userData field.
  89. #
  90. foreach button { { OK -ok }  { Cancel -cancel } { Help -help } } {
  91.     set name [lindex $button 0]
  92.     set option [lindex $button 1]
  93.     set buttonWidget [VtToggleButton $rc.$name \
  94.     -value 1 \
  95.     -userData $option\
  96.     ]
  97.     lappend buttons $buttonWidget
  98. }
  99. set buttonList [list $buttons]
  100.  
  101. set dialogCommandList \
  102.       "VtMessageDialog 
  103.        VtErrorDialog 
  104.        VtWarningDialog
  105.        VtInformationDialog
  106.        VtQuestionDialog
  107.        VtWorkingDialog"
  108.  
  109. set rcb [VtRowColumn $dlog.rcb \
  110.     -horizontal \
  111.     -packing COLUMN \
  112.     -numColumns 2\
  113.     -MOTIF_topOffset 10 \
  114.     ]
  115.  
  116. # Build the set of dialog-invoking buttons.
  117. #
  118. foreach dialogCommand $dialogCommandList {
  119.         VtPushButton $rcb.$dialogCommand \
  120.         -callback "mkDlog $dialogCommand $buttonList $textWidget"
  121. }
  122.  
  123. VtShowDialog $dlog
  124. VtMainLoop
  125.  
  126.